package com.ligq.common.utils

import android.content.Context
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException

object AvFileUtils {
    @Throws(IOException::class)
    fun copyAssets(context: Context, assetsName: String, path: String) {
        val assetFileDescriptor = context.assets.openFd(assetsName)
        val from = FileInputStream(assetFileDescriptor.fileDescriptor).channel
        val to = FileOutputStream(path).channel
        from.transferTo(assetFileDescriptor.startOffset, assetFileDescriptor.length, to)
    }

    fun getSampleData(low: Byte, high: Byte): Short {
        return ((low.toInt() and 0xff) or ((high.toInt() and 0xff) shl 8)).toShort()
    }

    fun getLowData(sampleData: Int): Byte {
        return (sampleData and 0xFF).toByte()
    }

    fun getHighData(sampleData: Int): Byte {
        return ((sampleData ushr 8) and 0xff).toByte()
    }
}